import org.I0Itec.zkclient.ZkClient;
import org.apache.zookeeper.CreateMode;

import java.io.IOException;
import java.util.List;

public class DistributedLock {
    public static void main(String[] args) {
        ZkClient zkClient = new ZkClient("192.168.254.140:2181", 100);
        zkClient.create("/ccc", "11", CreateMode.PERSISTENT_SEQUENTIAL);
        zkClient.subscribeChildChanges("/ccc",(parentPath, currentChilds) -> {
            System.out.println("监听变更:"+parentPath+"/"+currentChilds);

        });
        String s = zkClient.create("/ccc/11", "11", CreateMode.PERSISTENT_SEQUENTIAL);
        System.out.println("创建结点:" + s);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        zkClient.delete(s);
        System.out.println("删除结点:" + s);
        List<String> children = zkClient.getChildren("/ccc");
        System.out.println(children);
        try {
            System.in.read();
        } catch (IOException e) {
            e.printStackTrace();
        }
        zkClient.close();
//

    }
}
